package org.fujene.memman.backup;

import java.util.Arrays;

import org.fujene.structure.ContentInfo;
import org.fujene.structure.LookupPointer;

public class SnapShotStructure{
	// Dictionary, Invert index, Contents, Appendices: hold current pointer
	private LookupPointer dictPoint;
	private LookupPointer invIndexPoint;
	private LookupPointer skipPointerPoint;
	private LookupPointer[] contentPoints;
	private LookupPointer[] contentSkipPtrPoints;
	private LookupPointer[] appendixPoints;
	private boolean isToFile;
	private String storeDirectory;
	private boolean isCopyToNode;
	private int finalBlockNum;
	private long ID;

	private SnapShotStructure(){}

	public SnapShotStructure(ContentInfo contentInfo){
		this.contentPoints = new LookupPointer[contentInfo.getContentNum()];
		this.appendixPoints = new LookupPointer[contentInfo.getAppendixNum()];
		this.isToFile = false;
	}

	public SnapShotStructure(String dir){
		this.isToFile = true;
		this.storeDirectory = dir;
	}

	public static SnapShotStructure snapshotAll(LookupPointer dic, LookupPointer skipPtr,
			LookupPointer invindex, LookupPointer[] content, LookupPointer[] contentSkipPtr,
			LookupPointer[] appendix, long ID, int nextID){
		SnapShotStructure structure = new SnapShotStructure();

		structure.dictPoint = dic;
		structure.skipPointerPoint = skipPtr;
		structure.invIndexPoint = invindex;
		structure.contentPoints = Arrays.copyOf(content, content.length);
		structure.contentSkipPtrPoints = Arrays.copyOf(contentSkipPtr, contentSkipPtr.length);
		structure.appendixPoints = Arrays.copyOf(appendix, appendix.length);
		structure.ID = ID;
		structure.isToFile = false;
		structure.finalBlockNum = nextID;

		return structure;
	}

	public LookupPointer dictPoint(){
		return dictPoint;
	}
	
	public LookupPointer skipPtrPoint(){
		return skipPointerPoint;
	}

	public LookupPointer invIndexPoint(){
		return invIndexPoint;
	}

	public LookupPointer contentPoints(int index){
		return contentPoints[index];
	}

	public LookupPointer contentSkipPointerPoints(int index){
		return contentSkipPtrPoints[index];
	}

	public int contentNum(){
		return contentPoints.length;
	}

	public LookupPointer appendixPoints(int index){
		return appendixPoints[index];
	}

	public int appendixNum(){
		return appendixPoints.length;
	}

	public int getFinalBlockNum(){
		return finalBlockNum;
	}

	public void setBackupToDisk(String targetDir){
		isToFile = true;
		storeDirectory = targetDir;
	}
	
	public void copyToNode(){
		this.isCopyToNode = true;
	}

	public boolean isToFile(){
		return isToFile;
	}
	
	public boolean isCopyToNode() {
		return isCopyToNode;
	}

	public long getID(){
		return ID;
	}

	public String storeDirectory(){
		return storeDirectory;
	}
}
